package com.yolib.sanyi.connection.event;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import com.yolib.sanyi.tool.YoliBLog;

import android.content.Context;
import android.os.Bundle;
import android.os.Message;

public class TravelEvent extends ConnectionEvent{
	private String API_TYPE = "suggest";
	private List<NameValuePair> nameValuePairs;
	private Context mContext;
	public TravelEvent(Context context) {
		mContext =  context;
		nameValuePairs = new ArrayList<NameValuePair>();
	    nameValuePairs.add(new BasicNameValuePair("iType", API_TYPE));
	}
	
	public TravelEvent(Context context, String cId) {
		mContext =  context;
		nameValuePairs = new ArrayList<NameValuePair>();
	    nameValuePairs.add(new BasicNameValuePair("iType", API_TYPE));
	    nameValuePairs.add(new BasicNameValuePair("cId", cId));
	}

	@Override
	public void post() {
		YoliBLog.e("travel start:");

		String resp = httpPost(nameValuePairs, mContext);
		if(resp.compareTo(CONNECTION_ERROR) != 0)
		{
			if(mHandler != null)
			{
				YoliBLog.e("news resp:" + resp);
				
				Message msg = Message.obtain(mHandler);
				msg.what = ConnectionEvent.SUCCESS;
				msg.obj = resp;
				Bundle bundler = new Bundle();
				bundler.putString("class", TravelEvent.class.getName());
				msg.setData(bundler);
				mHandler.sendMessage(msg);
			}
			if(mSubEvent != null)
				mSubEvent.post();
		}
		else {
			if(mHandler != null)
				{
				Message msg = Message.obtain(mHandler);
				msg.what = ConnectionEvent.ERROR;
				msg.obj = resp;
				Bundle bundler = new Bundle();
				bundler.putString("class", TravelEvent.class.getName());
				msg.setData(bundler);
				mHandler.sendMessage(msg);
				}
		}
	}

}
